package com.yidu.ladder.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yidu.ladder.system.dao.UserDao;
import com.yidu.ladder.system.domain.Org;
import com.yidu.ladder.system.domain.User;
import com.yidu.ladder.system.domain.UserVo;
import com.yidu.ladder.system.service.UserService;

@Service
public class UserServiceimpl  implements UserService{
	@Autowired
	private UserDao userDao;
	

	public UserServiceimpl(UserDao userDao) {
		super();
		this.userDao = userDao;
	}


	public UserServiceimpl() {
	}


	public UserDao getTimeDao() {
		return userDao;
	}


	public void setTimeDao(UserDao userDao) {
		this.userDao = userDao;
	}
	@Override
	public Map<String, Object> pageQueryUser(UserVo userVo) {
		int page = (userVo.getPage() - 1) * userVo.getLimit();
		userVo.setPage(page);
		List<User> query = userDao.pageQueryUser(userVo);
		int count = userDao.countUserByCriteria(userVo);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("count", count);
		map.put("data", query);
		return map;
	}


	@Override
	public Boolean updateUserUseableById(String userIdstr, String flag) {
		Map<String, Object> paraMap = new HashMap<String, Object>();
		String useable = flag;
		String[] userIds = userIdstr.split(",");
		int total = 0;
		for (int i = 0; i < userIds.length; i++) {
			// 添加ID
			paraMap.put("userId", userIds[i]);
			// 添加要修改的状态
			paraMap.put("useable", useable);
			// 执行修改用户状态方法
			int result = userDao.updateUserUseableById(paraMap);
			// 计数
			total += result;
		}
		return total == userIds.length ? true : false;
	}


	@Override
	public int addUser(User user) {
		return userDao.addUser(user);
	}


	@Override
	public int updateUserById(User user) {
		return userDao.updateUserById(user);
	}


	
	/**
	 * 
	 * @Title: queryAllOrg
	 * @Description: 查询所有组织
	 * @return 
	 * @see com.yidu.ladder.system.service.UserService#queryAllOrg() 
	 * @author ChenLin
	 * @date 2019-12-04 09:29:07
	 */
	@Override
	public List<Org> queryAllOrg() {
		// TODO Auto-generated method stub
		return userDao.queryAllOrg();
	}

	
	/**
	 * 
	 * @Title: judgmentUserPhone
	 * @Description:根据手机号查询用户信息，判断用户是否存在
	 * @param userPhone 用户手机号
	 * @return  查询到的用户信息
	 * @see com.yidu.ladder.system.service.UserService#judgmentUserPhone(java.lang.String) 
	 * @author ChenLin
	 * @date 2019-12-06 02:12:07
	 */
	@Override
	public User toVerifyUserPhone(String userPhone) {
		
		return userDao.toVerifyUserPhone(userPhone);
	}


	@Override
	public User findUserById(String userId) {
		// TODO Auto-generated method stub
		return userDao.findUserById(userId);
	}


	@Override
	public int updatePassword(String userId, String password) {
		
		return userDao.updatePassword(userId, password);
	}


	




}
